/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Bas_Parameter",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using DGZImp.BasProject.DomainModels;
using DGZImp.BasProject.IServices;
using DGZImp.Core.Utilities.Response;
using DGZImp.BasProject.Services;
using Microsoft.AspNetCore.Authorization;

namespace DGZImp.BasProject.Controllers
{
    public partial class Bas_ParameterController
    {
        private readonly IBas_ParameterService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Bas_ParameterController(
            IBas_ParameterService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 根据moudle获取参数
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet("GetParamerIniByModule")]
        public async Task<ApiResponse<List<Bas_Parameter>>> GetParamerIniByModule(int module)
        {
            var res = await Service.GetParamerIniByModule(module);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 添加或修改参数
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost("AddOrUpdateParamter")]
        public async Task<ApiResponse<object>> AddOrUpdateParamter([FromBody] Bas_Parameter data)
        {
            var res = await Service.AddOrUpdateParamter(data);
            return ApiRes.SuccessMsg(res);
        }
        /// <summary>
        /// 如果是button类型，查询其对应的多行数据
        /// </summary>
        /// <param name="ParamModule"></param>
        /// <param name="ParamName"></param>
        /// <returns></returns>
        [HttpGet("GetParametersQuery")]
        public async Task<ApiResponse<List<Bas_Parameter>>> GetParametersQuery([FromQuery] int ParamModule, [FromQuery] string ParamName)
        {
            var res = await Service.GetParametersQuery(ParamModule, ParamName);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 批量添加或修改参数
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost("RangeAddOrUpdateParams")]
        public ApiResponse<bool> RangeAddOrUpdateParams([FromBody] List<Bas_Parameter> data)
        {
            var flag = Service.RangeAddOrUpdateParams(data);
            return ApiRes.Success(flag);
        }

        /// <summary>
        /// 根据id回显
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("GetParameterById")]
        public async Task<ApiResponse<Bas_Parameter>> GetParameterById(string Id)
        {
            var Bas_Parameter = await Service.GetParameterById(Id);
            return ApiRes.Success(Bas_Parameter);
        }

        /// <summary>
        /// 删除参数
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost("DeleteParameter")]
        public ApiResponse<object> DeleteParameter([FromBody] Bas_Parameter model)
        {
            var res = Service.DeleteParameter(model);
            return ApiRes.SuccessMsg(res);
        }


        /// <summary>
        /// 根据名称，类型获取数据
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        [HttpGet("QueryParamIniByNameAndType")]
        public async Task<ApiResponse<List<Bas_Parameter>>> QueryParamIniByNameAndType(string Name, int? Type)
        {
            var Bas_Parameter = await Service.QueryParamIniByNameAndType(Name, Type);
            return ApiRes.Success(Bas_Parameter);
        }
    }
}
